package com.szxw.BaiduAi.controller;

import com.szxw.BaiduAi.service.ImageService;
import com.szxw.BaiduAi.utils.FileUtils;
import com.szxw.BaiduAi.utils.MethodUtils;
import org.json.JSONObject;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 苏执小威
 * @Email:1410511702@qq.com
 * @Desc: 图片识别
 * @Date: 2022/9/23 14:24
 */
@WebServlet("/image")
public class ImageController extends BaiDuController {

     private ImageService service = new ImageService();

    /**
     * 该方法用于实现货币识别
     * @param req
     * @param resp
     * @throws IOException
     */
    public void currency(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //获取参数
        byte[] image = FileUtils.getFileDataByRequest(req);
        //调用接口进行地址识别并得到结果
        JSONObject address = service.currency(image);
        //将结果响应到前端
        MethodUtils.close(resp,address);

    }

    /**
     * 该方法用于实现动物识别
     * @param req
     * @param resp
     * @throws IOException
     */
    public void animal(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //获取参数
        byte[] image = FileUtils.getFileDataByRequest(req);
        //调用接口进行地址识别并得到结果
        JSONObject address = service.animalDetect(image);
        //将结果响应到前端
        MethodUtils.close(resp,address);

    }
    /**
     * 该方法用于实现动物识别
     * @param req
     * @param resp
     * @throws IOException
     */
    public void plant(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //获取参数
        byte[] image = FileUtils.getFileDataByRequest(req);
        //调用接口进行地址识别并得到结果
        JSONObject address = service.plantDetect(image);
        //将结果响应到前端
        MethodUtils.close(resp,address);

    }

}
